import TaskExpand from '@/views/transfer/job/components/TaskExpand'
export const taskColumns = _this => [
  {
    type: 'expand',
    width: 50,
    render: (h, params) => {
      const columnMapping = params.row.columnMapping
      const hasPermissions = _this.permissions_check

      return <TaskExpand rows={columnMapping} has-permissions={hasPermissions} />
    }
  },
  {
    title: '原表',
    key: 'source_table',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.sourceTable}</span>
    }
  },
  {
    title: '目标表',
    key: 'dest_table',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.destTable}</span>
    }
  },
  {
    title: '状态',
    key: 'status',
    sortable: true,
    render: (h, { row }) => {
      if (row.startTime && !row.endTime) {
        return <span><Tag color='primary'>执行中</Tag></span>
      } else if (row.startTime && row.endTime) {
        return <span><Tag color='green'>已完成</Tag></span>
      } else {
        return <span><Tag color='red'>未开始</Tag></span>
      }
      // return <span>{row.status}</span>
    }
  },
  {
    title: '任务平均流量',
    key: 'avg_rate',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.result.avgRate}</span>
    }
  },
  {
    title: '记录写入速度',
    key: 'write_speed',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.result.writeSpeed}</span>
    }
  },
  {
    title: '读出记录总数',
    key: 'record_total',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.result.recordTotal}</span>
    }
  },
  {
    title: '读写失败总数',
    key: 'record_error',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.result.recordError}</span>
    }
  },

  {
    title: '执行开始时间',
    key: 'start_time',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.startTime}</span>
    }
  },
  {
    title: '执行结束时间',
    key: 'end_time',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.endTime}</span>
    }
  },
  {
    title: '操作',
    key: 'action',
    fixed: 'right',
    render: (h, { row }) => {
      return <div>
        <el-link
          vOn:click={() => {
            _this.showTaskLogModal = true
            _this.taskInfo = row
            console.log(_this.showTaskLogModal)
          }} size='small' type='primary'>查看同步日志
        </el-link>
      </div>
    }
  }
]

export const taskChildColumns = _this => [
  {
    title: '原列表',
    key: 'source_column',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.sourceColumn}</span>
    }
  },
  {
    title: '目标列表',
    key: 'dest_column',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.destColumn}</span>
    }
  }
]
